package com.zonerobotics.zBotAPI.protocolMapping;

public final class VarMap {

	VarAccessLevel AccessType;
	/**
	 * size in bytes
	 */
	int size;
	/**
	 * position in list
	 */
	int position;
	/**
	 * offset in hw memory in bits
	 */
	int bitOffset;
	/**
	 * String name used for lookup
	 */
	public String name;
	
	//static for counting up
	static int offsetCnt = 0;
	static int positionCnt = 0;
	
	/**
	 * This creates a var map based off all these values
	 * @param accessType
	 * Access type ro, rw, other
	 * @param size
	 * size in bits
	 * @param position
	 * position in variables
	 * @param offset
	 * offset in bytes memory
	 * @param name
	 * name of variable
	 */
	public VarMap(VarAccessLevel accessType, int size, int position,
			int offset, String name) {
		AccessType = accessType;
		this.size = size/8;
		this.position = position;
		this.bitOffset = offset;
		this.name = name;
	}
	
	/**
	 * this adds in order filling out the position and offset, vars
	 * must be added in the correct order !
	 * @param accessType
	 * @param size
	 * @param name
	 */
	public VarMap(VarAccessLevel accessType, int size, String name) {
		AccessType = accessType;
		this.size = size/8;
		this.position = positionCnt;
		this.bitOffset = offsetCnt;
		this.name = name;
		positionCnt++;
		offsetCnt += size;
	}
	
	/**
	 * this resets the static vars so the counter restarts
	 */
	public static void resetVarMap()
	{
		offsetCnt = 0;
		positionCnt = 0;
	}

}
